package com.talent.jiwen.my;

import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.talent.jiwen.R;
import com.talent.jiwen.base.BaseActivity;
import com.talent.jiwen.http.common.ActivityLifeCycleEvent;
import com.talent.jiwen.http.common.ApiFactory;
import com.talent.jiwen.http.common.HttpUtil;
import com.talent.jiwen.http.common.ProgressSubscriber;
import com.talent.jiwen.http.result.DiscreditListResult;
import com.talent.jiwen.ui.widgets.NoEmojiEditText;
import com.talent.jiwen.util.SPUtil;
import com.talent.jiwen.util.Validators;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import rx.Observable;


/**
 * Created by qyqx on 2018/8/24.
 * 问题反馈
 */

public class FeedbackActivity extends BaseActivity {


    @BindView(R.id.edit_qus)
    NoEmojiEditText edit_qus;
    @BindView(R.id.submit)
    Button submit;



    @Override
    protected int provideContentViewId() {
        return R.layout.activity_feedback;
    }

    @Override
    public String titleName() {
        return "问题反馈";
    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.submit:
                String content = edit_qus.getText().toString();
                if (Validators.isEmpty(content)){
                    showToast("反馈信息不能为空");
                }else{
                    saveUserFeedBackInfo(content);
                }
                break;

        }
    }

    private void saveUserFeedBackInfo(String content){
        Map<String , String> map = new HashMap<>();
        map.put("studentId" , SPUtil.getUserId());
        map.put("feedbackMessage" , content);

        Observable observable = ApiFactory.getEducationApiSingleton().saveUserFeedBackInfo(SPUtil.getToken() , map);
        HttpUtil.getInstance().toSubscribe(observable, new ProgressSubscriber<Void>(FeedbackActivity.this) {
            @Override
            protected void _onNext(Void v) {
                showToast("反馈信息提交成功");
                finish();
            }

            @Override
            protected void _onError(String message) {

            }
        } , ActivityLifeCycleEvent.DESTROY , lifecycleSubject , true);
    }
}
